class Api::V1::PlansController < Api::V1::BaseController
  def index
    @plans = @current_user.plans
    if params[:state].presence
      @plans = @plans.where(state: params[:state])
    end
    @plans = @plans.order("created_at DESC").page(params[:page]).per(params[:per])
  end

  def show
    @plan = Plan.find params[:id]
  end

  def sum
    
  end

  def create
    @plan = @current_user.plans.build plan_params
    if @plan.save
      render json: { result: true, message: '创建计划成功.' }, status: :ok
    else
      render json: { result: false, message: '创建计划出错.' }, status: :ok
    end
  end

  private

  def plan_params
    params.require(:plan).permit(:name, :team_id)
  end
end
